(Music) Welcome to Client-side JavaScript
with DOM. After watching this video, you will be able
to describe the document object
model (DOM) hierarchy, describe the window and document objects, identify the DOM objects that are commonly
used in JavaScript applications for working with HTML documents. The document object model is the programming
interface between HTML or XHTML and JavaScript. The Document Object Model (DOM) is a browser-based
interface for applications and scripts to dynamically access and update the content,
structure, and style of documents. JavaScript uses the DOM to access and modify
web page elements in the web browser. The World Wide Web Consortium released four levels of the Document
Object Model specifications. Each successive level provides a more detailed
set of features for describing structured documents. The different browsers have various levels
of compatibility with the DOM standard. The discussion of the DOM in this unit focuses
on the DOM Level 1 Core and DOM Level 1 HTML APIs to access HTML elements with the DOM. The JavaScript engine in most web browsers
fully supports DOM level 1. Here is a representation of the basic DOM
model for browsers. The window object is at the top of the DOM
hierarchy and controls the environment that contains the document. The history object keeps internal details
about the recent history of pages in the browser. The history object has methods for letting
you simulate clicking the back or forward buttons in a browser. The location object contains information about
the URL of a page. The navigator is an object representation
of the client Internet browser or user agent. There is no standard that applies to the navigator
object, so the property values returned when running queries on the navigator object are
not consistent across browsers. The screen object is used to derive information
about a user's screen, such as the dimensions of the display screen. The screen object is useful for determining
the screen size of browser windows that run on mobile devices. The document object provides access to all
HTML elements within a page. Each HTML document that gets loaded into a
window becomes a document object. The window object is the outermost global
container of all the objects in the DOM hierarchy. When the browser loads a page, a window object
is automatically created for you. You can then access the window object properties
and functions from your JavaScript code. In client-side JavaScript, the Window object
serves as the global object and everything in the DOM takes place in a window. A number of predefined methods exist for the
window object. The window.alert,
window.confirm, and window.prompt dialogs that are used in web pages, come from the global window object. You can leave out the window prefix for methods
in the DOM API. So the window.alert method can be coded more simply as alert with a message
argument. This figure shows the object model for a simple
HTML document. Notice how the object hierarchy matches the
HTML containment hierarchy on the left. The object diagram can also be represented
as a tree structure that corresponds to the structure of the HTML document. The branches of the tree structure are termed
nodes. There are two types of nodes in the W3C DOM,
element nodes and text nodes. All HTML tags (html, head, meta, title, and
body) are element nodes. The nodes that contain actual text that go
between an element start tag and end tag, are text nodes. The figure shows the DOM level 2 tree for
the FORM portion of the document. The line feeds between elements are text nodes
and are part of the DOM level 2 tree. The DOM level 2 tree includes a line feed
text node before the paragraph and input elements. The input element includes a text node that
contains all the text that follows the input tag. An additional line feed text node follows
the input element. The DOM level 0 for the form portion of the
document would have only the form, p, and input boxes. The DOM level 2 adds the carriage returns,
tabs, and spaces, sometimes referred to as "white space". In this video, you learned: The document object model (DOM) is the programming
interface between HTML or XHTML and JavaScript. Each successive level of the DOM provides
a more detailed set of features for describing structured documents. Different browsers have different levels of
compatibility with the DOM standard. The basic DOM for browsers is a hierarchy
that includes objects that perform different functions. For example, the window object controls the
environment of the document, the location object contains information about the URL
of the page, screen object derives information about the user’s screen, and the document
object provides access to all HTML elements within a page. DOM levels define object types, with which
developers can build a variety of documents, from plain HTML documents for web pages, to
more complex forms.